Skip to content

Clear CommandCursorResult.results after next()/tryNext(). #1780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

vbabanin
Copy link
Member

@vbabanin vbabanin commented Aug 9, 2025

…aining consumed batches while cursor stays open.

JAVA-5940
@vbabanin vbabanin changed the title Clear CommandCursorResult.results after next()/tryNext() to avoid ret… Clear CommandCursorResult.results after next()/tryNext(). Aug 9, 2025
@vbabanin vbabanin assigned vbabanin and rozza and unassigned rozza Aug 9, 2025
@vbabanin vbabanin requested review from rozza and Copilot August 9, 2025 17:55
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses memory usage optimization by clearing the results list in CommandCursorResult after cursor operations. The change ensures that once results are consumed via next() or tryNext(), the internal results collection is emptied to prevent memory retention.

  • Adds a factory method to create CommandCursorResult instances with empty results
  • Modifies CommandBatchCursor to clear results after consumption
  • Introduces a private constructor for internal use in the factory method

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
CommandCursorResult.java Adds factory method and private constructor to support creating instances with empty results
CommandBatchCursor.java Clears commandCursorResult.results after consuming batch data in doNext()

@vbabanin vbabanin marked this pull request as ready for review August 10, 2025 17:29
@vbabanin vbabanin requested a review from a team as a code owner August 10, 2025 17:29
Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the AsyncCommandCursor also need this change?

@vbabanin
Copy link
Member Author

vbabanin commented Aug 11, 2025

Does the AsyncCommandCursor also need this change?

Good point, I’ve added the change for AsyncCommandCursor.

@vbabanin vbabanin requested a review from rozza August 11, 2025 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants